// pages/activity/activity.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    actIdx: '0',
    type: ['全部', '待签到', '已完成'],
    list: [
    ]
  },

  selectActivityTap: function(e) { //选择
    console.log(e)
    let that = this;
    let { list, all, isover, unover } = that.data;
    let actIdx = e.currentTarget.dataset.idx;
    console.log(actIdx)
    if (actIdx == 0) {
      list = all;
    } else if (actIdx == 1) {
      list = unover;
    } else {
      list = isover;
    }
    that.setData({
      actIdx,list
    })
  },
  openActiveDetail:function(e){
    wx.navigateTo({
      url: '/pages/activity-writeoff/activity-writeoff?id='+e.currentTarget.dataset.id,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this;
    let actIdx = options.actIdx;
    if (actIdx) {
      that.setData({
        actIdx
      })
    }
    that.getMyActive(); //活动列表

  },

  getMyActive: function() {
    var that = this;
    var params = {
      user_id: wx.getStorageSync('userId')
    };
    app.request(app.globalData.host + 'mine/getMyActive', params, 'GET', true,
      function(res) {
        console.log(res)
        var list =that.data.list;
        var actIdx = that.data.actIdx;
        if (actIdx==0){
          list = res.data.data.active.all
        } else if (actIdx == 1){
          list = res.data.data.active.unover
        }else{
          list = res.data.data.active.isover
        }
        that.setData({
          list: list,
          all: res.data.data.active.all,
          unover: res.data.data.active.unover,
          isover: res.data.data.active.isover,
        })
      },
      function(err) {},
      function(complete) {})

  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },


})